package com.touch.core.script;

import com.touch.core.Constants;

public abstract class ByteDecoder
{
	/** 
	 * Starts the Decoding process
	 * @param byteArray ByteArray containing the script.
	 */
	public void decode(ByteArray byteArray)
	{
		decode(byteArray.toArray());
	}
	/**
	 * Starts the Decoding process
	 * @param byteArray Array of bytes containing the script
	 */
	public void decode(byte[] byteArray)
	{
		final byte[] comCode = byteArray;				
		for(int a = 0; a < comCode.length; a++)
		{
			if(comCode[a] == Constants.com_START)
			{					
				final int offset_START = a + 1;
				for(int b = offset_START; b < comCode.length; b++)				
				{
					if(comCode[b] == Constants.com_END)					
					{
						final int offset_END = b;						
						final byte[] command = ByteEncoder.getSubByteArray(comCode, offset_START, offset_END);
						parser(new ByteArray(command));
						break;
					}
				}
			}
		}
	}
	public abstract void parser(ByteArray command);
}

